//
// Created by NASA on 2024-7-24.
// 按学生总成绩排序
//

#include <iostream>
#include <algorithm>

using namespace std;

struct student
{
    string name;
    double suba;
    double subb;
    double subc;
    double total;

    void sum()
    {
        total = suba + subb + subc;
    }
};

bool cmp(student a, student b)
{
    return a.total < b.total;
}

int main()
{

    int n = 4;
    student stus[n];
    stus[0] = {"a", 30, 20, 10};
    stus[1] = {"b", 90, 92, 90};
    stus[2] = {"c", 98, 99, 100};
    stus[3] = {"d", 2, 4, 3};
    // 计算总分数, 存入sum中
    for (int i = 0; i < n; ++i)
    {
        stus[i].sum();
    }
    // 按总分排序
    sort(stus, stus + n, cmp);
    for (int i = 0; i < n; ++i)
    {
        cout << stus[i].name << ' ';
    }
    return 0;
}